<template>
	<view>
		<view class="goods-item">
			<view class="goods-item-left">
				<!-- 添加radio  -->
				<radio :checked="goods.goods_state" color="#c00000" v-if="showRadio" @click="radioClickHandler"></radio>
				<image class="goods-item-left-img" :src="goods.goods_small_logo || defaultImg" mode="" @click="xx"></image>
			</view>
			<view class="goods-item-right">
				<view class="goods-name">{{goods.goods_name}}</view>
				<view class="goods-price-num">
					<view class="goods-price">￥{{goods.goods_price | toFixed}}</view>
					<uni-number-box :min="1" :value="goods.goods_count" background="#2979FF" color="#fff" v-if="showNum" @change="numChangeValue"></uni-number-box>
				</view>
			</view>
		</view>	
	</view>
</template>

<script>
	// import {mapMutations} from 'vuex'
	export default {
		name:"goods-item",
		props:{
			goods:{
				type:Object,
				default:{}
			},
			showRadio:{
				type:Boolean,
				default:false
			},
			showNum:{
				type:Boolean,
				default:false
			}
		},
		data() {
			return {
				defaultImg:"http://image3.suning.cn/uimg/b2c/newcatentries/0070061155-000000000617064184_1_200x200.jpg",
			};
		},
		filters:{
			toFixed(num){
				return Number(num).toFixed(2);
			}
		},
		methods:{
			// ...mapMutations('cart_m',['updateGoodsState']),
			xx(){
				this.$emit('click');
			},
			radioClickHandler(){
				console.log('xxx');
				const goods_id_state = {
					goods_id:this.goods.goods_id,
					// goods_state最新的值
					goods_state:!this.goods.goods_state,
				}
				// 获取到了最新的数据 goods_id_state  mutations跟新的方法
				// this.updateGoodsState(goods_id_state);
				// this.$emit('xx',goods_id_state);
				this.$emit('radioChange',goods_id_state);
			},
			numChangeValue(value){
				console.log(value);
				// 最新的value值  goods_id传递给父级 子传父
				this.$emit('numChange',{
					goods_id:this.goods.goods_id,
					goods_count:value
				})
			}
		}
	}
</script>

<style lang="scss">
.goods-item{
		display: flex;
		padding: 10px 5px;
		border-bottom: 1px solid #ccc;
		.goods-item-left{
			margin-right:10px;
			display: flex;
			align-items: center;
			.goods-item-left-img{
				width: 200rpx;
				height: 200rpx;
				display: block;
			}
		}
		.goods-item-right{
			.goods-price{
				font-size: 30px;
				color: #c00000;
			}
			.goods-price-num{
				display: flex;
				align-items: center;
				justify-content: space-between;
			}
		}
	}
</style>